//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.service;

import com.github.pagehelper.PageHelper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xw.dao.BannerMapper;
import com.xw.model.Banner;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class BannerServiceImpl implements BannerService {

    @Resource
    private BannerMapper bannerMapper;


    @Override
    public Map del(String id) {
        int flag = bannerMapper.deleteByPrimaryKey(id);
        return JsonData.returnMap(flag);
    }


    @Override
    public Map edit(Banner banner) {
        banner.setUpdateTime(new Date());
        int flag = bannerMapper.updateByPrimaryKeySelective(banner);
        return JsonData.returnMap(flag);
    }

    @Override
    public Banner findByKeyId(String bannerId) {
        return bannerMapper.selectByPrimaryKey(bannerId);
    }

    @Override
    public Map add(Banner banner) {
        banner.setBannerId(AppUtil.uuid());
        banner.setCreateTime(new Date());
        int flag = bannerMapper.insertSelective(banner);
        return JsonData.returnMap(flag);
    }

    @Override
    public List<Banner> findByWhere() {
        PageHelper.orderBy("sort");
        List<Banner> list = bannerMapper.findByWhere();
        return list;
    }
}
